﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;

using FerrSimplicity;
using Microsoft.Xna.Framework.Input;
using System.Xml;

namespace SampleApp
{
    class GameState : BaseGameState
    {
        BaseGameObject staticFish;
        public GameState(Game aGame)
            : base(aGame)
        {
        }

        public override void Initialize()
        {
            BaseGameObject swimFish  = new BaseGameObject(Game);
            //swimFish.Transform.Position2D = new Vector2(-600, 1800);

            ComActor2D     fishActor = new ComActor2D("fish", 128, 64);
            AnimFrame[]    swimAnim  = new AnimFrame[20];
            for (int i=0;i<20;i++)
                swimAnim[i] = new AnimFrame(i, 0.05f);

            fishActor.AddAnimation("default", swimAnim);
            swimFish.AddComponent(fishActor);

            ManagerPrefabs.Instance.Add("Fish", swimFish);

            Game.Components.Add(swimFish);

            staticFish = new BaseGameObject(Game);
            staticFish.Transform.Position2D = new Vector2(100, 100);
            staticFish.AddComponent(new ComSprite2D  ("fish", new Rectangle(0, 0, 128, 64)));
            staticFish.AddComponent(new ComForce(new Vector3(50, 0, 0), 0));
            staticFish.AddComponent(new ComScreenWrap());

            Game.Components.Add(staticFish);

            BaseGameObject camera = new BaseGameObject(Game);
            camera.AddComponent(new ComCamera("default"));
            camera.AddComponent(new ComOffset(swimFish, new Vector3(-400, -240, 0), 0.01f));

            Game.Components.Add(camera);


            for (int y = 0; y < Game.GraphicsDevice.Viewport.Height / 256 + 2; y++)
            {
                for (int x = 0; x < Game.GraphicsDevice.Viewport.Width / 256 + 2; x++)
                {
                    BaseGameObject tile = new BaseGameObject(Game);
                    tile.AddComponent(new ComSprite2D  ("GroundTile"));
                    tile.AddComponent(new ComScreenWrap());
                    tile.Transform.Position = new Vector3(x * 256, y * 256, 1.0f);
                    Game.Components.Add(tile);

                    BaseGameObject tFish = ManagerPrefabs.Instance.Create("Fish");
                    tFish.Transform.Position2D = new Vector2(x * 256, y * 256);
                    Game.Components.Add(tFish);
                }
            }

            base.Initialize();
        }

        public override void Update(GameTime aTime)
        {
            if (SystemInput.Instance.KeyJustDown(Keys.D))
            {
            }
            base.Update(aTime);
        }
    }
}
